package com.designpattern.obeserver.method1;

/**
 * @author: guoqiang.lv
 * @date: 2019/6/18
 * @description:
 */
public class ForecastDisplay implements DisplayElement, Obeserver {

    private Subject subject;

    private float temperature;

    public ForecastDisplay(Subject subject) {
        this.subject = subject;
        subject.registerObeserver(this);
    }

    @Override
    public void display() {
        System.out.println("湿度: " + temperature);
    }

    @Override
    public void update(Object args) {
        if (args instanceof WeatherData) {
            this.temperature = ((WeatherData) args).getHumidity();
            display();
        }
    }
}
